//
//  DYAudioPlay.m
//  DYLYJ
//
//  Created by JM on 15/11/13.
//  Copyright © 2015年 JM. All rights reserved.
//

#import "DYAudioPlay.h"
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
#import "DYSettingTool.h"
@interface DYAudioPlay()
@property(nonatomic,strong)AVAudioPlayer *upDownStopPlayer;
@property(nonatomic,strong)AVAudioPlayer *othenrPlayer;
@end

@implementation DYAudioPlay
singleton_implementation(DYAudioPlay)

- (instancetype)init
{
    self = [super init];
    if (self) {
        //1.音频文件的url路径
        NSURL *url=[[NSBundle mainBundle]URLForResource:@"上下停按钮音效.mp3" withExtension:Nil];
        
        //2.创建播放器（注意：一个AVAudioPlayer只能播放一个url）
        self.upDownStopPlayer=[[AVAudioPlayer alloc]initWithContentsOfURL:url error:Nil];
        //3.缓冲
        [self.upDownStopPlayer prepareToPlay];
        
        //1.音频文件的url路径
        NSURL *url2=[[NSBundle mainBundle]URLForResource:@"其他功能按钮音效.mp3" withExtension:Nil];
        
        //2.创建播放器（注意：一个AVAudioPlayer只能播放一个url）
        self.othenrPlayer=[[AVAudioPlayer alloc]initWithContentsOfURL:url2 error:Nil];
        //3.缓冲
        [self.othenrPlayer prepareToPlay];

    }
    return self;
}
- (void)playUpDownStop {
    if ([DYSettingTool boolForKey:DYSettingSoundSwitch] ){
        [self.upDownStopPlayer play];
    }
    if ([DYSettingTool boolForKey:DYSettingShockSwitch] ){
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    }
}
- (void)playOtherSound {
    if ([DYSettingTool boolForKey:DYSettingSoundSwitch] ){
        [self.othenrPlayer play];
    }
    if ([DYSettingTool boolForKey:DYSettingShockSwitch] ){
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
    }
}
@end
